package com.nbsaas.boot.cms.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.CatalogEntity;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;


@CatalogClass
@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "新闻分类", model = "新闻分类")
@Entity
@Table(name = "bs_news_catalog")
public class NewsCatalog extends CatalogEntity {

    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private NewsCatalog parent;

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    private List<NewsCatalog> children;

    @Override
    public Serializable getParentId() {
        if (parent != null) {
            return parent.getId();
        }
        return null;
    }
}
